var express = require('express');
var router = express.Router();

// 引入封装 mysql 查询函数
var db = require('../api/db');

/* GET users listing. */
router.get('/', function (req, res, next) {
  res.send('respond with a resource,个人中心......');
});

// 配置路由对象
router.get('/userList', (req, res, next) => {
  // sql查询user表
  console.log("获取参数",req.query)
  let params = req.query;
  let sql='select * from student where id=?';
  console.log("获取用户列表",params)
  if(!params.id)
  {
    sql='select * from student';
  }
  console.log(sql)
  db.query(sql, [params.id], function (results, fields) {
    // 以json的形式返回
    res.json({status: 200, msg: '查询成功', code: 0, count: results.length,  results })
  })
})

module.exports = router;
